package com.ly.hotel.util;

import java.io.File;
import java.io.IOException;
import java.util.List;

import com.ly.hotel.common.Constants;

import android.util.Log;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.FileHeader;

/**
 * 
 * @author ding 解压本地压缩文件
 * 
 */

public class ZipTools {
	/**
     * 
     * @param zipFileName
     *            压缩文件所在  路径+文件名+后缀
     * @param outputDirectory
     *            解压之后路径
     * @throws IOException
     */ 
    public static void unzip(String zipFileName, String outputDirectory) throws IOException {
    	try{
	    	ZipFile zipFile2 = new ZipFile(zipFileName);         
	    	if (zipFile2.isEncrypted()) {  
	    		Log.i("zip", "这是一个加密的插件.");    
	    	    zipFile2.setPassword("%lyfuckaishi%");  
//	    		zipFile2.setPassword("1234567");   
	    	}  
	    	List fileHeaderList = zipFile2.getFileHeaders();  
	    	
	    	File file = new File(Constants.CUSTOM_INTERFACE_ROOT);
	    	if(file.isDirectory() && !file.exists()){
	    		file.mkdirs();
	    	}
	    	
	    	for (int i = 0; i < fileHeaderList.size(); i++) {  
	    	    FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);  
	    	    zipFile2.extractFile(fileHeader, outputDirectory);  
	    	}  
    	}catch(ZipException e){
    		Log.e("zip", "解压失败:" + e.getMessage());
    	}
    }
}
